<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>条款文件导入</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	<script type="text/javascript">
	var startP = 1;
	
$(document).ready(function() {
	//上传条款文件事件
	$("#buttonUpload").click(function(){
		$.openLoading();
		var fileNameStr = $('#fileToUpload').val();
		fileNameStr = fileNameStr+"";
		var lastDotIndex = fileNameStr.lastIndexOf(".");
		var lastGunIndex = fileNameStr.lastIndexOf("\\");
		if(lastDotIndex==-1){
			$.closeLoading();
			$.message("error","请选择扩展名为 .docx 的文件上传");
			return;
		}else{
			var extName = fileNameStr.substring(lastDotIndex+1, fileNameStr.length);
			if(extName.toLowerCase() =="doc"){
				$.closeLoading();
				$.message("error","仅支持docx文档的转换与导入，请将此文档在word或wps中另存为.docx格式（请勿直接重命名，直接重命名后内容格式仍未改变，导入会出现错误）");
				return;
			}
			
			if(extName.toLowerCase() != "docx"){
				$.closeLoading();
				$.message("error","请选择扩展名为 .docx 的文件上传");
				return;
			}
			var coreProdCode = $('#coreProdCode').val();
			var healthInformName = $('#healthInformName').val();
			/* $.dialog1("warning","确认添加" + fileName + "条款文件？"){
				onCancel:return;
			} */
		}
		var param = {coreProdCode : coreProdCode , healthInformName : healthInformName};
		//存储前先确定，是否为更新
			$.ajax({
					url : '<%=path%>/nlifePlanConfig/isHealthInformExist',
					type : 'POST',
					async : true,
					data:param,
					dataType:'json',
					success:function(result){
						$.closeLoading();
						if(result.result=='success'){
							$.ajaxFileUpload({
						        url:'<%=path%>/nlifePlanConfig/HealthinformUpload',
						        fileElementId :'fileToUpload',//file控件id
						        dataType: 'json',
						        data:param,
						        success : function (data){
						        	$.closeLoading();
						        	if(data.result=="error"||data.result=="fail"){
						        		$.dialog({
							    			width: 358,
							    			top:40,
							    			modal:true,
							    			Close:true,
							    			cancel:null,
							    			content: data.message
							    		});
							        	return;
						        	}else{
						        		$.dialog({
							    			width: 358,
							    			top:40,
							    			modal:true,
							    			Close:true,
							    			cancel:null,
							    			content: "存储成功！ 条款代码：" + fileName + " ."
							    		});
						        	}
						        	if($.validate(data)) return;
						        	queryAgentMtInfo(1);
						        }
							});
						}else{
							$.dialog({
								type: "warn",
								content: "已存在该产品的健康告知，确认更新？",
								onOk: function() {
									$.openLoading();
									$.ajaxFileUpload({
								        url:'<%=path%>/nlifePlanConfig/HealthinformUpload',
								        fileElementId :'fileToUpload',//file控件id
								        dataType: 'json',
								        data:param,
								        success : function (data){
								        	$.closeLoading();
								        	if(data.result=="error"||data.result=="fail"){
								        		$.dialog({
									    			width: 358,
									    			top:40,
									    			modal:true,
									    			Close:true,
									    			cancel:null,
									    			content: data.message
									    		});
									        	return;
								        	}else{
								        		$.dialog({
									    			width: 358,
									    			top:40,
									    			modal:true,
									    			Close:true,
									    			cancel:null,
									    			content: "更新成功！ 条款代码：" + coreProdCode + " ."
									    		});
								        	}
								        	if($.validate(data)) return;
								        }
									});
								},
							onCancel:function(){
								return ;
							}
							})	
						}
					}
				})
		
		
		
		
		

	});
	
});
	
	
	
	
	
	

function previewRiskContent(obj){
	//点击预览窗口，展示条款文件；
	
	var riskCode = $(obj).parent('td').parent('tr')[0].childNodes[0].innerHTML;
	var param = {riskCode : riskCode};
	
	$.ajax({
		url : "prodManage/previewRiskContent",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(subPage) {
			 	$.closeLoading();
				$.dialog({
	    			width: 1000,
	    			height:600,
	    			modal:true,
	    			Close:true,
	    			cancel:null,
	    			content: subPage.message,
	    		});
				
			
				$(".xxDialog").css("overflow","scroll");
				return ;
		}	
	})
}
	
	
	</script>
</head>
<body>
	<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">扫码出单管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>条款文件导入
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
		
		<table class="table_02" id="table">
			<tr>
				<td>
					<table border="1" class="table_02" style="height:50px">
						<tr>
			  				<td width="60%" nowrap="nowrap">
			  					关联核心产品代码： <input type="text" id="coreProdCode" name="coreProdCode"><span style="color:red"> *</span>&nbsp;&nbsp;
			  				
			  					关联核心产品名称： <input type="text" id="coreProdName" name="coreProdName" disabled="disabled"><span style="color:red"> *</span>&nbsp;&nbsp;
			  				
			  					健康告知名称： <input type="text" id="healthInformName" name="healthInformName" ><span style="color:red"> *</span>
			  				</td>
			  				
			  			</tr>
						<tr>
			  				<td width="60%" nowrap="nowrap"><input  id="fileToUpload" name="myfiles" type='file' size='20'/><a href="javascript:void(0);" id="buttonUpload">&nbsp;&nbsp;导入条款文件&nbsp;&nbsp;</a>
			  				
			  				<span style="color:red"> *只支持.docx文档的导入 </span>
			  				</td>
			  				
			  			</tr>
			  			
					</table>
				</td>
			</tr>
		</table>
		
		
		
		
		
		<div id="Loading" style="display:none" align="center">
			<img src="./images/loading.gif" />
		</div>
		
	<!-- 结束 -->
</body>
</html>